<?php
/**
 * Created by PhpStorm.
 * User: JYuans
 * Date: 2019/12/2
 * Time: 14:04
 */
namespace Mhome\Controller;
use Common\Controller\BaseController;

class MhomeController extends BaseController {

    public $user_data;

    /**
     * 初始化方法
     */
    function _initialize(){
        $this->checkToken();
    }

    /**
     * 检查是否已经登录
     */
    protected function checkToken(){
        $token = $_REQUEST["token"]?$_REQUEST["token"]:$this->errorReturn("lack of token");

        $check_token = M("User")
            ->where(['token'=>$token])
            ->find();
        if(!$check_token){
            $this->returnJson(502,"token错误");
        }

        $this->user_data = $check_token;
    }
}